/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package scheduler;

import java.sql.ResultSet;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author JLLSco
 */
public class MainUI extends javax.swing.JFrame {

    /**
     * Creates new form MainUI
     */
    public MainUI() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToolBar1 = new javax.swing.JToolBar();
        viewUsersButton = new javax.swing.JButton();
        viewHairdressersButton = new javax.swing.JButton();
        deleteAppointmentButton = new javax.swing.JButton();
        scrollPane = new javax.swing.JScrollPane();
        infoBox = new javax.swing.JTextPane();
        addUserButton = new javax.swing.JButton();
        addAppointmentButton = new javax.swing.JButton();
        deleteUserButton = new javax.swing.JButton();
        addHairdresserButton = new javax.swing.JButton();
        deleteHairdresserButton = new javax.swing.JButton();
        viewAppointmentsButton = new javax.swing.JButton();
        MenuBar = new javax.swing.JMenuBar();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();

        jToolBar1.setRollover(true);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("JLLSCO Hairdressing");

        viewUsersButton.setText("View Users");
        viewUsersButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viewUsersButtonActionPerformed(evt);
            }
        });

        viewHairdressersButton.setText("View Hairdressers");
        viewHairdressersButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viewHairdressersButtonActionPerformed(evt);
            }
        });

        deleteAppointmentButton.setText("Delete Appointment");
        deleteAppointmentButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteAppointmentButtonActionPerformed(evt);
            }
        });

        scrollPane.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        infoBox.setBorder(null);
        infoBox.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        infoBox.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        infoBox.setEnabled(false);
        scrollPane.setViewportView(infoBox);

        addUserButton.setText("Add User");
        addUserButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addUserButtonActionPerformed(evt);
            }
        });

        addAppointmentButton.setText("Add Appointment");
        addAppointmentButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addAppointmentButtonActionPerformed(evt);
            }
        });

        deleteUserButton.setText("Delete User");
        deleteUserButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteUserButtonActionPerformed(evt);
            }
        });

        addHairdresserButton.setText("Add Hairdressers");
        addHairdresserButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addHairdresserButtonActionPerformed(evt);
            }
        });

        deleteHairdresserButton.setText("Delete Hairdresser");
        deleteHairdresserButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteHairdresserButtonActionPerformed(evt);
            }
        });

        viewAppointmentsButton.setText("View Appointments");
        viewAppointmentsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viewAppointmentsButtonActionPerformed(evt);
            }
        });

        jMenu2.setText("Administrator Options");

        jMenuItem2.setText("Preferences");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem2);

        MenuBar.add(jMenu2);

        setJMenuBar(MenuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(scrollPane)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(viewUsersButton, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(viewHairdressersButton, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(viewAppointmentsButton, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(36, 36, 36)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(addHairdresserButton, javax.swing.GroupLayout.DEFAULT_SIZE, 151, Short.MAX_VALUE)
                            .addComponent(addUserButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(addAppointmentButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(34, 34, 34)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(deleteUserButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(deleteHairdresserButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(deleteAppointmentButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(scrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 305, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(viewUsersButton)
                    .addComponent(addUserButton)
                    .addComponent(deleteUserButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(viewHairdressersButton)
                    .addComponent(addHairdresserButton)
                    .addComponent(deleteHairdresserButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(viewAppointmentsButton)
                    .addComponent(addAppointmentButton)
                    .addComponent(deleteAppointmentButton))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void viewUsersButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewUsersButtonActionPerformed
        DBHandler handler = new DBHandler();
        try {
            ResultSet resultSet = handler.readDataBase();
            int numberOfUsers = 0;
            String listOfUsers = "";
            while (resultSet.next()) {
                int userID = resultSet.getInt("USER_ID");
                String userFirstName = resultSet.getString("USER_FIRSTNAME");
                String userLastName = resultSet.getString("USER_LASTNAME");
                System.out.println("User id: " + userID);
                System.out.println("User Name: " + userFirstName + userLastName);
                listOfUsers += "UserID: " + userID + "\nFull Name: " + userFirstName +" "+ userLastName + "\n\n";
                numberOfUsers++;
            }
            infoBox.setText("There are " + numberOfUsers + " users in the database:\n\n" + listOfUsers);
            resultSet.close();
        } catch (Exception ex) {
            Logger.getLogger(MainUI.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_viewUsersButtonActionPerformed

    private void deleteAppointmentButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteAppointmentButtonActionPerformed
        // TODO add your handling code here:
        infoBox.setText("Not implemented yet.");
    }//GEN-LAST:event_deleteAppointmentButtonActionPerformed
    
    private void addUserButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addUserButtonActionPerformed
        UserRegistrationUI userRegistrationWindow = new UserRegistrationUI();
        userRegistrationWindow.setVisible(true);
    }//GEN-LAST:event_addUserButtonActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void viewHairdressersButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewHairdressersButtonActionPerformed
        DBHandler handler = new DBHandler();
        try {
            ResultSet resultSet = handler.readAdminTable();
            int numberOfHairdressers = 0;
            String listOfHairdressers = "";
            while (resultSet.next()) {
                int userID = resultSet.getInt("ADMIN_ID");
                String userFirstName = resultSet.getString("ADMIN_FIRSTNAME");
                String userLastName = resultSet.getString("ADMIN_LASTNAME");
                System.out.println("User id: " + userID);
                System.out.println("User Name: " + userFirstName + userLastName);
                listOfHairdressers += "UserID: " + userID + "\nFull Name: " + userFirstName +" "+ userLastName + "\n\n";
                numberOfHairdressers++;
            }
            infoBox.setText("There are " + numberOfHairdressers + " hairdressers in the database:\n\n" + listOfHairdressers);
            resultSet.close();
        } catch (Exception ex) {
            Logger.getLogger(MainUI.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_viewHairdressersButtonActionPerformed

    private void addAppointmentButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addAppointmentButtonActionPerformed
        MockAddAppointmentUI mockAppointmentUI = new MockAddAppointmentUI();
        mockAppointmentUI.setVisible(true);
    }//GEN-LAST:event_addAppointmentButtonActionPerformed

    private void deleteUserButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteUserButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_deleteUserButtonActionPerformed

    private void addHairdresserButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addHairdresserButtonActionPerformed
        HairdresserRegistrationUI hairdresserRegistrationWindow = new HairdresserRegistrationUI();
        hairdresserRegistrationWindow.setVisible(true);
    }//GEN-LAST:event_addHairdresserButtonActionPerformed

    private void deleteHairdresserButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteHairdresserButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_deleteHairdresserButtonActionPerformed

    private void viewAppointmentsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewAppointmentsButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_viewAppointmentsButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new MainUI().setVisible(true);
                
                
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuBar MenuBar;
    private javax.swing.JButton addAppointmentButton;
    private javax.swing.JButton addHairdresserButton;
    private javax.swing.JButton addUserButton;
    private javax.swing.JButton deleteAppointmentButton;
    private javax.swing.JButton deleteHairdresserButton;
    private javax.swing.JButton deleteUserButton;
    public javax.swing.JTextPane infoBox;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JScrollPane scrollPane;
    private javax.swing.JButton viewAppointmentsButton;
    private javax.swing.JButton viewHairdressersButton;
    private javax.swing.JButton viewUsersButton;
    // End of variables declaration//GEN-END:variables
}
